
let baseUrl = `${window.location.protocol}//${window.location.host}`;


if (import.meta.env.DEV) {
    baseUrl = 'http://localhost:3001';
}

export function getUrl(path: string) {
    return `${baseUrl}${path}`
}


export function dateFormat(timestamp: number) {
    const date = new Date(timestamp * 1000);
    const y = date.getFullYear();
    const m = date.getMonth() + 1;
    const d = date.getDate();
    const h = date.getHours();
    const me = date.getMinutes();
    const sec = date.getSeconds();
    return `${y}-${m}-${d} ${h}:${me}:${sec}`;
}

export function sizeFormat(size: number) {
    if (size < 1024) {
        return `${size}Byte`;
    } else if (size < 1024 * 1024) {
        const s = size / 1024;
        return `${s.toFixed(2)}KB`;
    } else if (size < 1024 * 1024 * 1024) {
        const s = size / 1024 / 1024;
        return `${s.toFixed(2)}MB`;
    } else {
        return `${size}Byte`;
    }
}
